﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ProjectEF6
{
    /// <summary>
    /// Interaction logic for Edituser.xaml
    /// </summary>
    public partial class EditCompany : Window
    {
        DB db = new DB();
        PanelA p = new PanelA();
        int id;
        public EditCompany(int Id, String Name, String Street, int Zipcode, String City, String Country, String Email, int Phone, int Employees)
        {
            this.id = Id;
            InitializeComponent();
            txtName.Text = Name;
            txtStreet.Text = Street;
            txtZipcode.Text = Zipcode.ToString();
            txtCity.Text = City;
            txtCountry.Text = Country;
            txtEmail.Text = Email;
            txtTelephone.Text = Phone.ToString();
            txtEmployees.Text = Employees.ToString();
        }

        private void btnAccept_Click(object sender, RoutedEventArgs e)
        {
            String insertName = txtName.Text;
            String insertStreet = txtStreet.Text;
            int insertZipcode = Convert.ToInt32(txtZipcode.Text);
            String insertCity = txtCity.Text;
            String insertCountry = txtCountry.Text;
            String insertEmail = txtEmail.Text;

            String tel = txtTelephone.Text.Replace(" ", String.Empty);
            String empl = txtEmployees.Text.Replace(" ", String.Empty);
            if (p.checkEmail(insertEmail) & p.checkTextfields(txtName.Text, txtStreet.Text, txtZipcode.Text, txtCity.Text, txtCountry.Text, txtEmail.Text, txtTelephone.Text, txtEmployees.Text) & p.IsAllDigits(txtTelephone.Text) & p.IsAllDigits(txtEmployees.Text))
            {
                int insertPhone = Convert.ToInt32(tel);
                int insertEmployees = Convert.ToInt32(empl);
                if (db.editCompany(id, insertName, insertStreet, insertZipcode, insertCity, insertCountry, insertEmail, insertPhone, insertEmployees))
                {
                    this.Close();
                }
            }
            
        }

    }
}
